#include "StdAfx.h"
#include "Model.h"



Model::Model(void)
{

}

Model::~Model(void)
{
	delete[] vertices;
	delete[] indices;
	
}


int Model::Load(char* file_nfg)
{
	FILE* file = fopen(file_nfg, "r");
	if (!file)
		return LOAD_FAILED;
	char tmp[20];
	int read_result = fscanf(file, "NrVertices: %d", &num_vertices);
	
	vertices = new Vertex[num_vertices];

	for (int j = 0; j < num_vertices; ++j)
	{
		fscanf(file, "%s pos:[%f, %f, %f]; norm:[%f, %f, %f]; binorm:[%f, %f, %f]; tgt:[%f, %f, %f]; uv:[%f, %f];\n", tmp,
			&vertices[j].pos.x, &vertices[j].pos.y, &vertices[j].pos.z, &vertices[j].normal.x, &vertices[j].normal.y, &vertices[j].normal.z
	, &vertices[j].binormal.x,&vertices[j].binormal.y, &vertices[j].binormal.z,	&vertices[j].tangent.x, &vertices[j].tangent.y, &vertices[j].tangent.z
	, &vertices[j].uv.x, &vertices[j].uv.y);
	}
	fscanf(file, "NrIndices: %i", &num_indices);
	indices = new GLushort[num_indices];
	for (int j = 0; j < num_indices / 3; ++j)
	{
		fscanf(file, "%s%d, %d, %d\n", tmp, &indices[3 * j], &indices[3 * j + 1], &indices[3 * j + 2]);
	}
	return LOAD_SUCCEEDED;
}

